//
//  VBVisitorView.swift
//  VBo
//
//  Created by 赵世得 on 2016/10/23.
//  Copyright © 2016年 Zh. All rights reserved.
//

import UIKit

class VBVisitorView: UIView {
    var closure: (()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func loginClick(){
        closure?()
    }
    
    func setUpVisitorViewInfo(imgName: String?, title: String?){
        if let img = imgName, let tit = title {
            iconImageView.image = UIImage(named: img)
            massageLabel.text = tit
            circelImageView.isHidden = true
        }else{
            setupCircleImageViewAnim()
        }
        
    }
    
    private func setupCircleImageViewAnim(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        anim.duration = 20
        anim.repeatCount = MAXFLOAT
        anim.isRemovedOnCompletion = false
        circelImageView.layer.add(anim, forKey: nil)
    }
    
    private func setUpUI(){
        backgroundColor = UIColor(white: 237/255, alpha: 1)
        addSubview(circelImageView)
        addSubview(maskImageView)
        addSubview(iconImageView)
        addSubview(massageLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)
        
        circelImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        maskImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        iconImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        massageLabel.snp_makeConstraints { (make) in
            make.width.equalTo(230)
            make.centerX.equalTo(self)
            make.top.equalTo(iconImageView.snp_bottom).offset(16)
        }
        registerBtn.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 100, height: 35))
            make.top.equalTo(massageLabel.snp_bottom).offset(16)
            make.left.equalTo(massageLabel)
        }
        loginBtn.snp_makeConstraints { (make) in
            make.size.top.equalTo(registerBtn)
            make.right.equalTo(massageLabel)
        }
    }
    
    fileprivate lazy var circelImageView = UIImageView(imgname: "visitordiscover_feed_image_smallicon")
    fileprivate lazy var maskImageView = UIImageView(imgname: "visitordiscover_feed_mask_smallicon")
    fileprivate lazy var iconImageView = UIImageView(imgname: "visitordiscover_feed_image_house")
    fileprivate lazy var massageLabel: UILabel = {
        let lab = UILabel(text: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜", font: 14, textColor: UIColor.darkGray)
        lab.numberOfLines = 0
        lab.textAlignment = .center
        return lab
    }()
    fileprivate lazy var registerBtn: UIButton = {
        let btn = UIButton(setImg: "common_button_white", title: "注册", font: 14, textColor: UIColor.darkGray, target: self, action: #selector(loginClick))
        return btn
    }()
    
    fileprivate lazy var loginBtn: UIButton = {
        let btn = UIButton(setImg: "common_button_white", title: "登录", font: 14, textColor: UIColor.darkGray, target: self, action: #selector(loginClick))
        return btn
    }()

}
